#include <stdio.h>
#include <stdlib.h>

#include "ExtremeC_examples_chapter7_2_player.h"
#include "ExtremeC_examples_chapter7_2_gun.h"

int main(int argc, char** argv) {
    //创建并构造 gun 对象
    struct gun_t* gun = gun_new();
    gun_ctor(gun, 3);

    //创建并构造 player 对象
    struct player_t* player = player_new();
    player_ctor(player, "Billy");

    //开始聚合关系
    player_pickup_gun(player, gun);
    //开火，直到子弹都不剩为止
    while (gun_has_bullets(gun)) {
        player_shoot(player);
    }

    //重装弹
    gun_refill(gun);
    //开火，直到子弹都不剩为止
    while (gun_has_bullets(gun)) {
        player_shoot(player);
    }

    //结束聚合关系
    player_drop_gun(player);

    //析构并释放 player 对象
    player_dtor(player);
    free(player);

    //析构并释放 gun 对象
    gun_dtor(gun);
    free(gun);

    return 0;
}